﻿
using Microsoft.EntityFrameworkCore.Metadata;
using Models.Common;
using Models.Device;
using Models.TaskPlain;
using NetTaste;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Drawing2D;
using System.IO.Ports;
using System.Text;
using System.Threading;
using UtilsORM;
using UtilsORM.MySqlData;
using static Models.Common.EnumDeviceState;

using UtilsBase;
using GatewayServerService.CloudCenter;

namespace GatewayServerService.Device
{
    /// <summary>
    /// //普锐森社-	大气压
    /// </summary>
    public class ServiceDeviceRS4851031_QY
    {

        //回调获获状态,为了避免误差，查状态和执行，都返回了 当前开关状态
        public void callBackUpdate(MQReqModel<object> httpReqModel)
        {
            try
            {
                ServiceCloudDeviceValueLog log = new ServiceCloudDeviceValueLog();
                ModelReceverData modelDeviceData = httpReqModel.toServerData;
                CommandLogModel commandLogModel = httpReqModel.toGatewayData;
                string result = modelDeviceData.commandResults[0].value;

                if (commandLogModel.key == "atmosphere" && !string.IsNullOrWhiteSpace(result))
                {
                    //01 03 04 00 97 xx xx
                    string dataHex1 = result.Substring(9, 5);
                    double atmosphere = new UtilsDataTypeChange().hex16Convert10(dataHex1) * 0.1;
                    log.writeSensorlog(commandLogModel.d_guid, "atmosphere", atmosphere.ToString(), "大气压");
                }


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

    }

}
